export const getImgElements = (itemElements) => {
  const ImgElements = []

  itemElements.forEach((item) => {
    ImgElements.push(item.querySelector('img'))
  })

  return ImgElements
}

export const getAllImg = (ImgElements) => {
  return ImgElements.map((item) => {
    return item.src
  })
}

export const onComplateImgs = (imgs) => {
  return Promise.all(imgs.map((item) => {
    return new Promise((resolve, reject) => {
      const img = new Image()
      img.src = item
      img.onload = () => {
        resolve({
          img: item,
          index: imgs.indexOf(item)
        })
      }
    })
  }))
}

export const getMinHeight = (columnHeightObj) => {
  const columnHeightArr = Object.values(columnHeightObj)
  return Math.min(...columnHeightArr)
}

export const getMaxHeight = (columnHeightObj) => {
  const columnHeightArr = Object.values(columnHeightObj)
  return Math.max(...columnHeightArr)
}

export const getMinHeightColumn = (columnHeightObj) => {
  const minHeight = getMinHeight(columnHeightObj)
  return Object.keys(columnHeightObj).find((key) => {
    return columnHeightObj[key] === minHeight
  })
}